<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Promise</title>
  </head>
  <body>
    <script>
      /* const p = new Promise((resolve, reject) => {
        reject('error')
      })
      p.catch((obj) => {
        console.log('1', obj)
        return Promise.resolve('catch1');
      }).then((res) => {
        console.log('2', res)
      })

      Promise.reject(123)
        .then((res) => {
          console.log('5', res)
          return 1
        })
        .catch((err) => {
          console.log('3', err)
        })
        .then((res) => {
          console.log('4', res)
        })  */
      /* async function async1() {
      console.log('async1 start');
      await async2();
      console.log('async1 end');
    }
    async function async2 () {
      console.log('async2');
    }
    console.log('script start');
    setTimeout(function(){
      console.log('setTimeout');
    })
    async1();
    new Promise(function(resolve){
      console.log('promise1');
      resolve();
    }).then(function(){
      console.log('promise2')
    })
    console.log('script end'); */
      new Promise((resolve, reject) => {
        console.log('promise')
        resolve()
      })
        .then(() => {
          // 执行.then的时候生成一个promise是给最后一个.then的
          console.log('then1')
          new Promise((resolve, reject) => {
            console.log('then1promise')
            resolve()
          })
            .then(() => {
              // 执行这个.then的时候，生成的promise是下面一个then的
              console.log('then1then1')
            })
            .then(() => {
              console.log('then1then2')
            })
        })
        .then(() => {
          // 这个
          console.log('then2')
        })
    </script>
  </body>
</html>
